#!/usr/bin/env python3
# author: Liujie
# date: 2023-06-24

import sys, os, re

if len(sys.argv) < 3:
    print("Usage: python script.py <server_day> <target_dir>")
    sys.exit(1)

server_day = sys.argv[1].strip("/")
target_dir = sys.argv[2]

my_list = []

def recursion_dir(dir_path):
    for file_name in os.listdir(dir_path):
        if file_name.startswith('.'):
            continue
        path = os.path.join(dir_path, file_name)
        if os.path.isdir(path):
            recursion_dir(path)
        elif re.search(r'\.(py|ipynb)$', file_name):
            my_list.append(path)

recursion_dir(target_dir)

tar_name = "刘杰.tar.gz"
print(f"打包文件名: {tar_name}")
print("待打包文件:")
for f in my_list:
    print("  " + f)

os.system(f'tar czf {tar_name} ' + " ".join(my_list))

scp_cmd = f'scp {tar_name} py11@8.155.27.170:~/day{server_day}'
print(f"上传命令: {scp_cmd}")
os.system(scp_cmd)

print('✅ 提交成功')
